/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.delivery.dto;

import com.mycompany.delivery.validation.ContactDTOConstraint;
import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.NumberFormat;
import org.springframework.format.annotation.NumberFormat.Style;

/**
 *
 * @author Jana Nemcova
 */
@ContactDTOConstraint
public class ContactDTO implements Serializable,Cloneable{
    private static final long serialVersionUID = 1L;
    
    private Long id;
    
    @NotNull
    @Size(min = 2, max = 20)
    private String name;

    @NotNull
    @Size(min = 2, max = 20)
    private String surname;
    
    @Email
    @NotNull
    private String email;
 
    @NotNull
    private String city;
    
    @NotNull
    private String street;
     
    @NotNull
    @Size(min = 5, max = 10)
    private String zip;
    
    @NotNull
    @Size(min = 6, max = 20)
    private String phone;

    public ContactDTO() {
        
    }

    public ContactDTO(Long id, String name, String surname, String email, String city, String street, String zip, String phone) {
        this.id = id;
        this.name = name;
        this.surname = surname;
        this.email = email;
        this.city = city;
        this.street = street;
        this.zip = zip;
        this.phone = phone;
    }
       

    public void setName(String name) {
        this.name = name;
    }
    

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public void setEmail(String email)  {
       // Pattern p =Pattern.compile("[a-zA-Z0-9_.]*@[a-zA-Z]*.[a-zA-Z]*");
       // Matcher m = p.matcher(email);
      //  if(!m.matches())
      //  {
      //      throw new IllegalArgumentException("Email isn't valid");
      //  }
        this.email = email;
        
        
    }


    public void setCity(String city) {
        this.city = city;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public void setPhone(String phone) {
     //   Pattern p =Pattern.compile("^[0-9+]{6,15}$");
     //   Matcher m = p.matcher(phone);
     //   if(!m.matches())
     //   {
      //      throw new IllegalArgumentException("Phone isn't valid");
      //  }
        this.phone = phone;
    }
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public String getSurname() {
        return surname;
    }

   public String getEmail() {
        return email;
    }

    public String getCity() {
        return city;
    }

    public String getStreet() {
        return street;
    }

    public String getZip() {
        return zip;
    }

    public String getPhone() {
        return phone;
    }
        
     @Override
    public int hashCode() {
        int hash = 7;
        hash = (id != null ? id.hashCode() : 0) + 43 * hash;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ContactDTO other = (ContactDTO) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ContactDTO: " + "id=" + id + ", name=" + name + ", surname=" + surname + ", email=" + email + ", adress=" + city + ", phone=" + phone;
    }
}
